<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;

class CommonController extends Controller
{
    //
    public function  login()
    {
    	//显示后台登录页面
    	return  view('admin.login');
    }

    public function  dologin(Request $request)
    {
    	//读取用户信息
    	$res = DB::table('user')->where('username',$request->input('username'))->first();
    	if(!$res){
    		// dd(666);
    		return back();
    	}else{
    		//检测密码
    		if(Hash::check($request->input('password'),$res->password)){
    			//写入session 跳转后台首页
    			session(['id'=>$res->id]);
    			return  redirect('/user/index');
    		}else{
    			return  back();

    		}
    	}
    }
}
